﻿using ConsoleApplication2.Dao;
using ConsoleApplication2.job;
using ConsoleApplication2.pushApi;
using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            bool b = false;
            print("开始监听"+DateTime.Now);
            //从工厂中获取一个调度器实例化
            IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
            init();

            scheduler.Start();       //开启调度器

            IJobDetail job1 = JobBuilder.Create<VideoBooking>()  //创建一个作业
               .WithIdentity("作业名称", "作业组")
               .Build();

            ITrigger trigger1 = TriggerBuilder.Create()
                                        .WithIdentity("触发器名称", "触发器组")
                                        .StartNow()                        //现在开始
                                        .WithCronSchedule("0 */10 * ? * *")  //每隔一定的时间执行
                                        .Build();


            scheduler.ScheduleJob(job1, trigger1);      //把作业，触发器加入调度器。


            
            JobFactory jobFactory = new JobFactory();
            JobCreateFactory createFactory = new JobCreateFactory();

            if (b)
            {
                // "/5 * * ? * *"    5秒执行一次
                jobFactory.ScheduleJob(createFactory.CreateIJobDetail<ExamArrangmentJob>(), createFactory.CreateTrigger("/0 0 9 * * ?"));
                jobFactory.ScheduleJob(createFactory.CreateIJobDetail<ExamRecordJob>(), createFactory.CreateTrigger("/0 5 * ? * *"));
                jobFactory.ScheduleJob(createFactory.CreateIJobDetail<MyStudyProgressJob>(), createFactory.CreateTrigger("*/1 * * ? * *"));

                jobFactory.ScheduleJob(createFactory.CreateIJobDetail<ExamArrangmentJob>(), createFactory.CreateTrigger("/0 0 9 * * ?"));

            }
            else
            {
                T_MsgCmd.sendNewMsg();
                ExamArrangmentCmd.selectFinish();
            }

            Console.ReadLine();
        }

        /// <summary>
        /// 初始化代码 
        /// </summary>
        static void init()
        {
           ExamArrangmentCmd.init(); 
        }


        static void print(String message)
        {
            Console.WriteLine(message);
        }
    }
}
